package com.chengzhi.web.controller;

import com.chengzhi.web.entity.DocBean;
import com.chengzhi.web.service.EsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @description
 * @author: ruanchengzhi
 * @create: 2020-12-24 11:01
 **/
@RestController
@RequestMapping("/es/api")
public class EsController {

    @Autowired
    private EsService esService;

    @PostMapping
    public ResponseEntity init() {
//        esService.createIndex();
        List<DocBean> list =new ArrayList<>();
        list.add(new DocBean(1L,"XX0193","XX8064","xxxxxx",1));
        list.add(new DocBean(2L,"XX0210","XX7475","xxxxxxxxxx",1));
        list.add(new DocBean(3L,"XX0257","XX8097","xxxxxxxxxxxxxxxxxx",1));
        esService.saveAll(list);
        return ResponseEntity.ok(1);
    }

    @GetMapping
    public ResponseEntity<List<DocBean>> all() {
        return ResponseEntity.ok(esService.selectAll());
    }

}
